#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File    ：connect
# @Author  ：曹庆
# @Date    ：2024/8/6 21:25
import pymysql


class DatabaseConnection:
    def __init__(self, host, user, password, database):
        self.connection = pymysql.connect(
            host=host,
            user=user,
            password=password,
            database=database,
            cursorclass=pymysql.cursors.DictCursor,
        )

    def get_connection(self):
        return self.connection

    def get_table_comment(self, table):
        self.connection
        return {}

    def get_data(self, table, limit=0, offset=0):
        comment = self.get_table_comment(table)
        query = f'SELECT * FROM {table} limit {limit} offset {offset}'
        params = (table, limit, offset)
        with self.connection() as cursor:
            cursor.execute(query, params)
            result = cursor.fetchall()
        return result
